package 笔试.荣耀;

import java.util.Scanner;

public class Demo01 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int mod = 1000000007;
        while(true){
            //0到n
            int n = in.nextInt();
            //1到l位
            int l = in.nextInt();
            if(n==0 && l==0){
                break;
            }else{
                long res = 0;
                long cur = 1;
                for(int i=1;i<=l;i++){
                    cur = (cur*n)%mod;
                    res = (res+cur)%mod;
                }
                System.out.println(res);
            }
        }
    }
}
